<?php

namespace app\model;

use DateTimeInterface;
use Illuminate\Database\Eloquent\SoftDeletes;
use Illuminate\Support\Str;
use support\Model;

class Base extends Model
{

    use SoftDeletes;

    protected $primaryKey = 'id';
    protected $guarded = [];

    protected static function boot(): void
    {
        parent::boot();

        self::creating(function ($model) {
            $model->ulid = 'BQ' . Str::ulid();
        });
        self::created(function ($model) {
            $model->update([
                'ulid' => 10000 + $model->id,
            ]);
        });
    }


    /**
     * 为数组 / JSON 序列化准备日期。
     *
     * @param DateTimeInterface $date
     * @return string
     */
    protected function serializeDate(DateTimeInterface $date): string
    {
        return $date->format($this->dateFormat ?: 'Y-m-d H:i:s');
    }

}